﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DreamBox.Admin.File
{
    public partial class FileAdd : BLL.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                DAL.PSelect ps = new DAL.PSelect();
                drop_UrlClass.DataSource = ps.Select("dbox_FileClass", "*", "");
                drop_UrlClass.DataTextField = "CName";
                drop_UrlClass.DataValueField = "CID";
                drop_UrlClass.DataBind();
            }
        }

        protected void btn_Post_Click(object sender, EventArgs e)
        {
            Model.FileContents m = new Model.FileContents();
            m.CID = int.Parse(drop_UrlClass.SelectedValue);
            m.Title = tbox_Title.Text.Trim();
            //m.Url = tbox_Url.Text.Trim();
            m.Contents = Contents.Text.Trim();
            m.Sort = int.Parse(tbox_Sort.Text.Trim());
            m.BrowseCount = 0;
            m.IsStatus = cbox_IsStatus.Checked;
            m.Plus = 0;
            m.PostDate = DateTime.Now;
            m.Property = 0;
            m.UserID = 2;

            DAL.MAction action = new DAL.MAction();
            if (action.Insert(m))
            {
                if (tbox_Url.Text != "")
                {
                    DAL.PSelect ps = new DAL.PSelect();
                    DataTable dt=ps.Select("dbox_FileContents", "top 1 FileID", "FileID>0 order by FileID desc");
                    int FileID = int.Parse(dt.Rows[0]["FileID"].ToString());
                    Model.FileUrl mUrl = new Model.FileUrl();
                    mUrl.FileID = FileID;
                    mUrl.Title = "本站下载";
                    mUrl.Url = tbox_Url.Text;
                    mUrl.UserID = 2;
                    mUrl.IsStatus = true;
                    mUrl.BrowseCount = 0;
                    mUrl.Description = "";
                    mUrl.IsType = true;
                    action.Insert(mUrl);
                }
                BLL.Admin.Tips.DetailedTips(this, "操作成功", "/File/FileAdd.aspx", "1");
                //Response.Write("<script>alert('操作成功');windown.location.href=windown.location.href;</script>");
            }
        }
    }
}